<template>
	<view class="content">
		<view class="order-item">
			<view class="goods-box-single">
				<image class="goods-img" :src="images" mode="aspectFill"></image>
				<view class="right position-relative">
					<view class="flex">
						<text class="title">{{ productInfo.name }}</text>
						<view class="title-right">
							<!--<view class="price">{{ productInfo.price }}</view>-->
							<view class="attr-box">{{ productInfo.type_name }}</view>
						</view>
					</view>
				</view>
			</view>
			<view>
				<view class="flex_item zhil">
					<view style="width: 20%;height: 40rpx;line-height: 40rpx;float: left;font-size: 28rpx;">产品描述</view>
					<view style="margin-top: 20rpx;;float: left;" ><uniRate text="1" size="20" margin="10" :value="rateValue1" @change="rateChange1"></uniRate></view>
			         <view style="float: left;margin-left:60rpx;color: #FF7427;">{{eva}}</view>
				</view>
				<view class="equity_box">
					<view class="text-box uni-textarea">
						<textarea placeholder-style="color:#999" :placeholder="placeholder" @blur="bindTextAreaBlur"></textarea>
					</view>
					<view class="">
						<view class="add-img-box flex_item">
							<view class="add-img-item" v-for="(item, index) in imgList" :key="index">
								<image class="add-imgs" @click.stop="imgInfo(index)" :src="item" mode=""></image>
								<image class="add-img-del" @click.stop="delImg(index)" src="/static/img/delete.png"></image>
							</view>
							<view v-if="imgList.length < 9" class="add-img-item" @click="scImgs()">
								<image class="add-img" src="../../static/clq-image/add.png"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view @click.stop="submit" class="address-box submit-box"><text class="submit-btn">保存</text></view>
	</view>
</template>

<script>
	import {
		ajax
	} from '../../ajax.js';
import uniRate from '@/components/uni-rate/uni-rate.vue';
export default {
	components: {
		uniRate
	},
	data() {
		return {
			list: '', //订单详情
			productInfo: {images:[]},
			text: '', //评论内容
			placeholder: '请输入您的评价内容',
			imgList: [],
			unique: '', //商品唯一标识码
			cloudimgList: [],
			cloudimg:'',
			rateValue1:5, //商品质量
			rateValue2: '', //服务态度
			imgCount: 6 ,//最多支持9张上传，可以修改
			id:'',
			images:'',
			good_id:'',
			eva:'好'
		};
	},
	onLoad(option) {
		this.unique = option.id;
		this.id=option.id
		this.loadOrder();
	},
	onShow() {},
	methods: {
		//text
		bindTextAreaBlur: function(e) {
			this.text = e.detail.value;
		},
		//获取收入支出信息
		loadOrder() {
			
			let that = this
			uni.showLoading({
				title: "加载中"
			})
			ajax({
				url: 'order/getOrder',
				data: {
					token: uni.getStorageSync('token'),
					order_id: that.id
				},
				header: {
					'content-type': 'application/json' //自定义请求头信息
				},
				method: 'POST',
				success: function(res) {
					uni.hideLoading()
					//res.data.data.status='501'
					let result = res.data.data
					if (res.data.code == 1) {
						that.list = res.data;
						that.productInfo = res.data.data;
						that.good_id=res.data.data.good_id;
						that.images=res.data.data.images[0]
						console.log(res.data.data.images[0])
					} else if (res.data.code == 0) {
						uni.showToast({
							title: res.data.msg,
							duration: 1500,
							icon: 'none'
						});
					} else if (res.data.code == -1) {
						uni.reLaunch({
							url: '/pages/clq_login/clq_login'
						})
					} else if (res.data.code == -2) {
						uni.showToast({
							title: res.data.msg,
							duration: 1500,
							icon: 'none'
						});
					}
				},
				error: function() {
					uni.showToast({
						title: res.data.msg,
						duration: 1500,
						icon: 'none'
					});
				}
			});
			
			
		},
		//商品质量评分
		rateChange1(val) {
			console.log(val)
			this.rateValue1 = val.value;
			if(this.rateValue1==1){
				this.eva='差'
			}else if(this.rateValue1==2){
				this.eva='中'
			}else if(this.rateValue1==3){
				this.eva='中'
			}else if(this.rateValue1==4){
				this.eva='中'
			}else if(this.rateValue1==5){
				this.eva='好'
			}
		},
		//服务态度评分
		rateChange2(val) {
			this.rateValue2 = val.value;
		},
	   //上传图片
		scImgs() {
		let self = this;
		uni.chooseImage({
			count: 1, //仅上传一张
			sizeType: ['compressed'], //original 原图，compressed 压缩图
			success: function(res) {
				let imgsFiles = res.tempFilePaths[0];
				//self.images = imgsFiles;
				//文件上传
				uni.uploadFile({
					url:'http://ice-outdoor.com.cn/app.php/upload/upload', //远程服务器的地址
					filePath: imgsFiles,
					name: 'file',
					success: function(res1) {
						let rs = eval('(' + res1.data + ')');
					    console.log(rs);
						if(rs.code==1){
							self.imgList.push(rs.data.url);
							console.log(self.imgList,'imgList')
							self.imgCount = 10 - self.imgList.length;
							console.log(self.imgCount ,'imgCount ')
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 1500,
								icon: 'none'
							});
						}
					
					},
					fail: function(e) {
						console.log(e);
					}
				});
			}
		});
		},
		//单张上传图片
		scImg() {
			let obj = this;
			if (obj.imgCount == 0) {
				uni.showToast({
					title: '最多添加6张图片',
					icon: 'none'
				});
				return;
			}
			
			ajax({
				url: 'upload/upload',
				formData:formData,
				data: {
					token: uni.getStorageSync('token'),
				},
				header: {
					'content-type': 'application/json' //自定义请求头信息
				},
				method: 'POST',
				success: function(res) {
					
				},
				error: function() {
					uni.showToast({
						title: res.data.msg,
						duration: 1500,
						icon: 'none'
					});
				}
			});
			
		},
		//提交评论
		submit(e) {
			let obj = this;
			if(obj.text==''){
				uni.showToast({
					title:'请输入评价内容',
					duration: 1500,
					icon: 'none'
				});
				return
			}
			for (let i = 0; i < obj.imgList.length; i++) {
				obj.cloudimg=obj.cloudimg+obj.imgList[i]+','
			}
			ajax({
				url: 'order/addEvaluate',
				data: {
					token: uni.getStorageSync('token'),
					order_id:obj.id,
					good_id:obj.good_id,
					content:obj.text,
					star:obj.rateValue1,
					images:obj.cloudimg
				},
				header: {
					'content-type': 'application/json' //自定义请求头信息
				},
				method: 'POST',
				success: function(res) {
					if(res.data.code==1){
						uni.showToast({
							title: '评价成功',
							duration: 1500,
							icon: 'none'
						});
						uni.navigateBack({
							
						})
					}else{
						uni.showToast({
							title: res.data.msg,
							duration: 1500,
							icon: 'none'
						});
					}
					
				},
				error: function() {
					uni.showToast({
						title: res.data.msg,
						duration: 1500,
						icon: 'none'
					});
				}
			});
		},
		//点击图片显示大图
		imgInfo(i) {
			let tempList = [];
			console.log(111);
			this.imgList.forEach(e => {
				tempList.push(e.url);
			});
			console.log(tempList);
			//显示图片
			uni.previewImage({
				current: i,
				loop: false,
				urls: tempList,
				indicator: 'default'
			});
		},
		//删除图片
		delImg(i) {
			uni.showModal({
				content: '确定删除这张吗',
				success: res => {
					if (res.confirm) {
						this.imgList.splice(i, 1);
						this.imgCount++;
					} else if (res.cancel) {
					}
				}
			});
		},
		// 页面跳转
		navto(e) {
			uni.navigateTo({
				url: e
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background: #ffffff;
	height: 100%;
	.content {
		background: #ffffff;
		height: 100%;
	}
}
/* 多条商品 */
.order-item {
	display: flex;
	flex-direction: column;
	padding: 0rpx 30rpx;
	background: #fff;
	margin-top: 20rpx;
	/* 单条商品 */
	.goods-box-single {
		display: flex;
		padding: 20rpx 0;
		.goods-img {
			display: block;
			width: 120rpx;
			height: 120rpx;
			border-radius: 20rpx;
		}
		.right {
			flex: 1;
			display: flex;
			flex-direction: column;
			padding: 0 30rpx 0 24rpx;
			overflow: hidden;
			height: 100%;
			.title {
				align-self: flex-start;
				font-size:  20px;
				color:#333;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 30rpx;
				overflow:hidden; 
				text-overflow:ellipsis;
				display:-webkit-box; 
				-webkit-box-orient:vertical;
				-webkit-line-clamp:2; 
			}
			.title-right {
				flex-shrink: 0;
				text-align: left;
				align-self: flex-start;
			}
			.attr-box {
				font-size:28rpx;
				color: #333;
			}
			.price {
				font-size:20rpx;
				color: #333;
				&:before {
					content: '￥';
					font-size: 12rpx;
					margin: 0 2rpx 0 8rpx;
				}
			}
		}
	}
}
.equity_box {
	background-color: #fafafa;
	border-radius: 10rpx;
	padding: 25rpx 25rpx;
	margin: 25rpx 0rpx;
	.text-box {
		height: 200rpx;
		textarea {
			font-size: 25rpx;
			width: 100%;
			height: 100%;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 5;
		}
	}
}
.zhil {
	font-size: 28rpx !important;
	padding: 32rpx 15rpx;
}
.submit-box {
	bottom: 0;
	left: 0;
	width: 750rpx;
}
.submit-btn {
	margin: 10px auto auto auto;
	display: inline-block;
	width: 550rpx;
	height: 96rpx;
	line-height: 96rpx;
	text-align: center;
	background-color: #FF7427 !important;
	opacity: 1;
	border-radius: 32rpx;
	border-width: 8rpx;
	border-color: rgba(255, 255, 255, 1);
	box-shadow: 0rpx 8rpx 12rpx rgba(0, 0, 0, 0.16);
	border-radius: 56rpx;
	font-size: 39rpx;
	font-weight: bold;
	color: rgba(255, 255, 255, 1);
}
.submit-btn-txt {
	font-size: 39rpx;
	font-weight: bold;
	line-height: 47rpx;
	color: rgba(255, 255, 255, 1);
	opacity: 1;
}
.map-box {
	width: 484rpx;
	height: 256rpx;
	border-width: 4rpx;
	border-color: rgba(255, 255, 255, 1);
	box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.16);
	/* border-radius: 12rpx; */
	position: relative;
}
.map {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	width: 476rpx;
	height: 250rpx;
}
.map-img {
	position: absolute;
	top: 90rpx;
	left: 156rpx;
	width: 230rpx;
	height: 68rpx;
	background-color: rgba(51, 51, 51, 0.64);
	border-width: 1rpx;
	border-color: rgba(0, 0, 0, 0);
	border-radius: 34px;

	font-size: 28rpx;
	font-weight: bold;
	line-height: 66rpx;
	color: rgba(255, 255, 255, 1);
	text-align: center;
}
.address-box {
	margin: 10rpx auto auto auto;
	width: 550rpx;
	height: 96rpx;
	line-height: 96rpx;
	text-align: center;
}
.label {
	font-size: 36rpx;
	font-weight: bold;
	line-height: 50rpx;
	color: #222222;
}
.label-img {
	padding-left: 40rpx;
}
.add-box {
	padding: 15rpx 0;
	flex-wrap: wrap;
}
.add-img-box {
	width: 100%;
	flex-direction: row;
	flex-wrap: wrap;
	margin-top: 50rpx;
}
.add-img-item {
	width: 138rpx;
	height: 138rpx;
	position: relative;
	line-height: 138rpx;
	text-align: center;
	background: #E5E5E5;
	display: inline-block;
	margin: 20rpx 20rpx;
	.add-img {
		width: 50%;
		margin: 0rpx auto;
		height: 50%;
		vertical-align: middle;
		border-radius: 24rpx;
		display: inline-block;
	}
	.add-imgs {
		width: 100%;
		margin: 0rpx auto;
		height: 100%;
		vertical-align: middle;
		border-radius: 24rpx;
		display: inline-block;
	}
}
.add-img-camera {
	flex: 1;
}
.add-img-del {
	position: absolute;
	width: 40rpx;
	height: 40rpx;
	left: 155rpx;
	bottom: 155rpx;
	//background-color: rgba(238, 0, 0, 1);
	border-radius: 20rpx;
}
.address-time {
	width: 484rpx;
	height: 88rpx;
	background-color: rgba(245, 245, 245, 1);
	opacity: 1;
	border-radius: 24rpx;
	text-align: center;

	font-size: 35rpx;
	font-weight: 500;
	color: rgba(51, 51, 51, 1);
}
.line {
	width: 750rpx;
	height: 1px;
	transform: scaleY(0.3);
	background-color: rgba(0, 0, 0, 0.5);
}
</style>
